﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InfonavaEye.components
{
    /// <summary>
    /// 按钮
    /// </summary>
    public class UniButton : Button
    {

        /// <summary>
        /// 正常前景色
        /// （相对于禁用状态）
        /// </summary>
        private Color normalForeColor = Color.Empty;

        /// <summary>
        /// 正常背景色
        /// （相对于禁用状态）
        /// </summary>
        private Color normalBackColor = Color.Empty;
        /// <summary>
        /// 自定义按钮
        /// </summary>
        public UniButton()
        {
           /* this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.FlatAppearance.BorderColor = Color.White;
            this.FlatAppearance.BorderSize = 1;
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.TextAlign = ContentAlignment.MiddleCenter;

            this.Font = new Font("黑体", 9f);
            this.ForeColor = Color.White;
            //this.BackgroundImage = WApp.util.Ui.assistant.UIResurece.Own.ImgButtonNormal;
            this.Size = new Size(102, 32);*/
        }

        private Graphics g = null;

        /// <summary>
        /// 此组件的前景色，用于显示文本
        /// </summary>
        [Browsable(true), Category("外观"), Description("此组件的前景色，用于显示文本")]
        public new Color ForeColor
        {
            get { return base.ForeColor; }
            set
            {
                if (this.enabled)
                    base.ForeColor = value;
            }
        }

        /// <summary>
        /// 此组件的背景色，用于显示文本
        /// </summary>
        [Browsable(true), Category("外观"), Description("此组件的背景色，用于显示文本")]
        public new Color BackColor
        {
            get { return base.BackColor; }
            set
            {
                if (this.enabled)
                    base.BackColor = value;
            }
        }

        /// <summary>
        /// 禁用状态下的前景色
        /// </summary>
        [Browsable(true), Category("外观"), Description("禁用状态下的前景色")]
        public Color DisabledForeColor {
            get;set;
        }

        /// <summary>
        /// 禁用状态下的背景色
        /// </summary>
        [Browsable(true), Category("外观"), Description("禁用状态下的背景色")]
        public Color DisabledBackColor
        {
            get; set;
        }

        private bool enabled = true;
        /// <summary>
        /// 指示是否已启用该控件，如果要使用原有的Enabled禁用控件，需要设置EnabledSet达到目的，EnabledSet级别高于此属性级别
        /// </summary>
        [Browsable(true), Category("行为"), Description("指示是否已启用该控件")]
        public new bool Enabled
        {
            get { return enabled; }
            set
            {
                if(normalForeColor.Equals(Color.Empty))
                {
                    normalForeColor = this.ForeColor;
                    normalBackColor = this.BackColor;
                }
                enabled = value;
                base.Enabled = false;
                if (value == false)
                {
                    base.ForeColor = DisabledForeColor;
                    base.BackColor = DisabledBackColor;
                }
                else
                {
                    this.ForeColor = normalForeColor;
                    this.BackColor = normalBackColor;
                }
                base.Enabled = enabled;
            }
        }

        /// <summary>
        /// Enabled其否启用该控件
        /// </summary>
        public bool EnabledSet
        {
            get { return base.Enabled; }
            set { base.Enabled = value; }
        }

        protected override void OnClick(EventArgs e)
        {
            if (this.enabled)
                base.OnClick(e);
        }

        protected override void OnDoubleClick(EventArgs e)
        {
            if (this.enabled)
                base.OnDoubleClick(e);
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (this.enabled)
                base.OnMouseClick(e);
        }

        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (this.enabled)
                base.OnMouseDoubleClick(e);
        }

        /// <summary>
        /// 鼠标进入变换背景图片
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseEnter(EventArgs e)
        {
            if (this.enabled)
            {
                base.OnMouseEnter(e);
                //this.BackgroundImage = WApp.util.Ui.assistant.UIResurece.Own.ImgButtonSelected;
            }
        }

        /// <summary>
        /// 鼠标离开变换背景图片
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseLeave(EventArgs e)
        {
            if (this.enabled)
            {
                base.OnMouseLeave(e);
                //this.BackgroundImage = WApp.util.Ui.assistant.UIResurece.Own.ImgButtonNormal;
            }
        }
    }
}
